package ${basePkg}.${beanName};

import com.wenzheng.workflow.tools.ActionResult;
import com.wenzheng.workflow.tools.ActionValues;
import javax.servlet.http.HttpServletRequest;
import org.springframework.ui.Model;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import ${basePkg}.${beanName}.bean.${BeanName};
import ${basePkg}.${beanName}.service.${BeanName}Service;

/**
 * ${tabComment!""}
 * @author zyt 控制器
 *
 */
@RestController
@RequestMapping("/${beanName}")
public class ${BeanName}Action {

    @Autowired
    private ${BeanName}Service ${beanName}Service; 


    
	@PostMapping("insert")
	public ActionResult insert(${BeanName} ${beanName}){
		${beanName}Service.insert(${beanName});
		return ActionResult.Success();
	}
	
	
	
	@PostMapping("update")
	public ActionResult update(${BeanName} ${beanName}){
		${beanName}Service.update(${beanName});
		return ActionResult.Success();
	}


    
	@GetMapping("get")
	public ActionResult get(${priKeyType!"String"} ${priKey!"id"}){
		${BeanName} r=${beanName}Service.get(${priKey!"id"});
		return ActionResult.Success(r);
	}
	
	
	@PostMapping("delete")
	public ActionResult delete(@RequestParam(value="${priKey!"id"}",required=false)${priKeyType!"String"} ${priKey!"id"},@RequestParam(value="ids",required=false)String ids){
		
		<#if priKeyType=='String'>
		if(null!=${priKey!"id"}&&${priKey!"id"}.trim().length()>0){
			${beanName}Service.delete(${priKey!"id"});	
		}
		<#else>
		if(null!=${priKey!"id"}&&${priKey!"id"}>0){
			${beanName}Service.delete(${priKey!"id"});	
		}
		</#if>
		
		if(null!=ids&&ids.length()>0){
			${beanName}Service.batchDelete(ids.split(","));
		}
		
		return ActionResult.Success();
	}
				
	
	@GetMapping("query")
	public ActionResult query(@RequestBody ActionValues values){
		return ActionResult.Success(${beanName}Service.query(values));
	}
     

}